package code._16reflect._07add;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Demo2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException {
        Class<?> c = Class.forName("code._16reflect.bean.Person");
        String name = c.getName();
        System.out.println("name = " + name);

        String simpleName = c.getSimpleName();
        System.out.println("simpleName = " + simpleName);

        ClassLoader classLoader = c.getClassLoader();
        System.out.println("classLoader = " + classLoader);

        Class<?> superclass = c.getSuperclass();
        System.out.println("superclass = " + superclass);

        //获取接口
        Class<?>[] interfaces = c.getInterfaces();
        for (Class<?> anInterface : interfaces) {
            System.out.println("anInterface = " + anInterface);
        }

        //获取成员变量
        Field nameField = c.getDeclaredField("name");
        Class<?> type = nameField.getType();
        System.out.println("type.getSimpleName() = " + type.getSimpleName());
        int modifiers = nameField.getModifiers();
        System.out.println("modifiers = " + modifiers);
        String mod = Modifier.toString(modifiers);
        System.out.println("mod = " + mod);

        //获取方法对象
        Method eatMethod = c.getDeclaredMethod("eat", String.class);
        for (Class<?> parameterType : eatMethod.getParameterTypes()) {
            System.out.println("parameterType.getSimpleName() = " + parameterType.getSimpleName());

        }

        Class<?> returnType = eatMethod.getReturnType();
        System.out.println("returnType = " + returnType);

    }
}
